/**
 * 模拟U函数
 * @param url
 * @param params
 * @returns {string}
 * @constructor
 */
function U(url, params, rewrite) {
    (window.Think.DEEP == '' || window.Think.DEEP == 'undefined') ? window.Think.DEEP = '/' : '';
    if (window.Think.MODEL[0] == 2) {
        var website = window.Think.ROOT + '/';
        url = url.split('/');

        if (url[0] == '' || url[0] == '@')
            url[0] = APPNAME;
        if (!url[1])
            url[1] = 'Index';
        if (!url[2])
            url[2] = 'index';

        website = website + '' + url[0] + window.Think.DEEP + url[1] + window.Think.DEEP + url[2];
        if (params) {
            params = params.join('-');
            website = website + window.Think.DEEP + params;
        }
        if (!rewrite) {
            website = website + '.html';
        }

    } else {
        var website = window.Think.ROOT + '/index.php';
        url = url.split('/');
        if (url[0] == '' || url[0] == '@')
            url[0] = APPNAME;
        if (!url[1])
            url[1] = 'Index';
        if (!url[2])
            url[2] = 'index';
        website = website + '?s=/' + url[0] + window.Think.DEEP + url[1] + window.Think.DEEP + url[2];
        if (params) {
            params = params.join('/');
            website = website + window.Think.DEEP + params;
        }
        if (!rewrite) {
            website = website + '.html';
        }
    }

    return website;
}


$(function(){
            //商品分类切换时
             $("#cate").change(function(){        
               var cate_id = $(this).val();
               $.ajax({
                    type:'GET',
                    data:{cate_id:cate_id}, 
                    url:U("Home/Index/ajaxGetGoodBrand"),
                    success:function(data){                            
                           $("#brand").html('')
                           $("#brand").append(data);
                    }
               });
             });    

            //商品品牌切换时
            $("#brand").change(function(){        
             var brand_id = $(this).val();
             $.ajax({
                    type:'GET',
                    data:{brand_id:brand_id}, 
                    url:U("Home/Index/ajaxGetGoodModel"),
                    success:function(data){                            
                           $("#model").html('')
                           $("#model").append(data);
                    }
            });           
           
          });

       //搜索功能
        $("#search").click(function(){
            var url =$(this).parents('form').attr('action');
            var query  = $(this).parents('form').serialize();
             $.ajax({
                    type:'POST',
                    data:query, 
                    url:url,
                    success:function(data){                            
                           $("#good_list").html('')
                           $("#good_list").append(data);
                    }
            });
            return false;       
        });

        $("#bid_search").click(function(){
            var show_div=$(".tab-content").find('div[class*=active]');
            var url =show_div.attr('data-action');
            var query  = $(this).parents('form').serialize();
            $.ajax({
                type:'POST',
                data:query,
                url:url,
                success:function(data){
                    show_div.find("table").html('')
                    show_div.find("table").append(data);
                }
            });
            return false;
        })

     //重置功能
     $("#refresh").click(function(){
        $(':input','#search_form')  
         .not(':button, :submit, :reset, :hidden')  
         .val('')  
         .removeAttr('checked')  
         .removeAttr('selected');  
     });

        //提交表单
    $("#submitForm").click(function(){
        var url =$(this).parents('form').attr('action');
        var data  = $(this).parents('form').serialize();
        $.ajax({
            type:'POST',
            data:data,
            url:url,
            success:function(data){
                if(data.status==1){
                    layer.msg(data.info, {icon: 6});
                    window.location.href=data.url;
                }else{
                    layer.msg(data.info, {icon: 5});
                }
            }
        });
        return false;
    })


  })

 function showBidUser(self) {
     var wrap=self.parents('.w_clink_tableleft');
     if(wrap.hasClass('collope_active')){
         self.html('查看详情>')
         wrap.removeClass('collope_active').find('.user_bid_list').hide();
     }else{
         self.html('收起>>')
         wrap.addClass('collope_active').find('.user_bid_list').show();
     }
 }

 function showInput(self){

   self.parent().hide();
   $("#user_input").show();
 }